/*
 * drv_pwm.c
 *
 *  Created on: 2025年4月7日
 *      Author: 22332
 */
#include "drv_pwm.h"

status_t status = STATUS_SUCCESS;
void bsp_drv_pwm_init(void)
{
	  /* Initialize PWM */
	  status = PWM_Init(&pwm_pal_1_instance, &pwm_pal_1_configs);
	  DEV_ASSERT(status == STATUS_SUCCESS);
}
void bsp_drv_pwm_deinit(void)
{
	status = PWM_Deinit(&pwm_pal_1_instance);
	DEV_ASSERT(status == STATUS_SUCCESS);
}

/*
 * 说明:做热保护实验时,PWM为最大值255时,亮度为1072;PWM值为230时,pwm占空比为90%,亮度值为975
 * 客户要求以90%亮度为最大值,所以才有下面的230*duty/period。
 */
void bsp_drv_change_duty(uint32_t duty)
{
	uint32_t period = pwm_pal_1_configs.pwmChannels[0].period;
	if(duty > period)
		duty = period;
	duty = 230*duty/period;
	uint8_t channel = pwm_pal_1_configs.pwmChannels[0].channel;
	pwm_pal_1_configs.pwmChannels[0].duty = duty;
	status = PWM_UpdateDuty(&pwm_pal_1_instance, channel, duty);
    DEV_ASSERT(status == STATUS_SUCCESS);
}
